#! /bin/sh
. ./common.sh

# https://ohmyz.sh/
if ! command -v zsh >/dev/null 2>&1; then
    info "not installed zsh, will install it now!"
    si zsh
fi

rm -rf ~/.oh-my-zsh ~/ohmyzsh
ZSH_PATH="/home/$(whoami)"
if [ "$(whoami)" = "root" ]; then
  ZSH_PATH="/root"
fi
echo "oh-my-zsh install path: ${ZSH_PATH}"
info "install oh-my-zsh"
git clone https://gitee.com/studyzy/ohmyzsh.git ~/ohmyzsh
export ZSH="${ZSH_PATH}/.oh-my-zsh"
echo "ZSH path is: ${ZSH}"
# FIXME: 如何使安装过程中不弹出选择zsh作为默认shell来避免安装中断，后面的shell脚本执行不了？？
sh ~/ohmyzsh/tools/install.sh
# git clone https://gitee.com/LeoLinux/zsh-syntax-highlighting.git ${ZSH}/custom/plugins/zsh-syntax-highlighting
# git clone https://gitee.com/skarner/zsh-autosuggestions.git ${ZSH}/custom/plugins/zsh-autosuggestions
# git clone --depth=1 https://gitee.com/LeoLinux/powerlevel10k.git ${ZSH}/custom/themes/powerlevel10k
# git clone https://gitee.com/yanzhongqian/git-open.git ${ZSH}/custom/plugins/git-open
git clone https://gitee.com/Kurt-Code/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://gitee.com/Kurt-Code/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
git clone https://gitee.com/yanzhongqian/git-open.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/git-open
git clone https://gitee.com/lgf1244/packer-zsh-completion.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/packer
sed -i 's/^plugins=(/plugins=(docker docker-compose python npm zsh-autosuggestions zsh-syntax-highlighting z packer /' ~/.zshrc
sed -i 's/^ZSH_THEME="robbyrussell"/ZSH_THEME="juanghurtado"/' ~/.zshrc
# sed: -e expression #1, unknown option to `s'解决办法 https://blog.csdn.net/qq1124794084/article/details/76419464
ZSH_RAW="export ZSH=\"\$HOME/.oh-my-zsh\""
ZSH_HOME="export ZSH=\"$ZSH_PATH/.oh-my-zsh\""
echo "ZSH_RAW path is: ${ZSH_RAW}"
sed -i "s|$ZSH_RAW|$ZSH_HOME|g" ~/.zshrc
rm -rf  ~/ohmyzsh
